import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import App from './App.vue';
import router from './router';
import store from './store';
import '@/styles/index.scss';
//合入代码部分
import i18n from '@/i18n/index.js';
import '@/router/permission.js';
// 统一导入el-icon图标
import * as ElIconModules from '@element-plus/icons-vue';
// main.js中 引入安装
import { disAutoConnect } from 'vue-plugin-hiprint';
disAutoConnect();

import locale from 'element-plus/lib/locale/lang/zh-cn';

const app = createApp(App);
// 统一注册el-icon图标
for (let iconName in ElIconModules) {
  app.component(iconName, ElIconModules[iconName]);
}
//添加自定义指令
app.directive('btnpermission', {
  // 当被绑定的元素插入到 DOM 中时……
  mounted(el, binding) {
    const { value } = binding;
    let x = sessionStorage.getItem('roleExtraPer');
    let ary = Array.from(JSON.parse(x));
    // Focus the element
    if (ary.indexOf(value) > -1) {
      el.disabled = false;
    } else {
      el.disabled = true;
      el.classList.add('is-disabled');
    }
  },
});

// 原型上绑定store
app.config.globalProperties.$store = store;

app
  .use(ElementPlus, { locale })
  // .use(hiPrintPlugin, "$pluginName")
  .use(store)
  .use(router)
  .use(i18n)
  .mount('#app');
